/*
 * Potri.cs
 * 
 * Copyright (c) 2003-2004, dnAnalytics. All rights reserved.
*/

#if !MANAGED
using System;
using System.Runtime.InteropServices;

using dnA.Utility;

namespace dnA.Math.Lapack{
	[System.Security.SuppressUnmanagedCodeSecurityAttribute]
	internal sealed class Potri{
		private Potri(){}
		
		private static void ArgumentCheck(UpLo uplo, int n, object A, int lda){
			if (n<0) 
				throw new ArgumentException("n must be at least zero.", "n");
			if (A==null) 
				throw new ArgumentNullException("A","A cannot be null.");
			if (lda<n || lda<1) 
				throw new ArgumentException("lda must be at least max(1,n)", "lda");
		}
		
		internal static int Compute( UpLo uplo, int n, float[] A, int lda  ){
			ArgumentCheck(uplo, n, A, lda);
			return dna_lapack_spotri(uplo, n, A, lda);
		}

		internal static int Compute( UpLo uplo, int n, double[] A, int lda  ){
			ArgumentCheck(uplo, n, A, lda);
			return dna_lapack_dpotri(uplo, n, A, lda);
		}

		internal static int Compute( UpLo uplo, int n, ComplexFloat[] A, int lda  ){
			ArgumentCheck(uplo, n, A, lda);
			return dna_lapack_cpotri(uplo, n, A, lda);
		}

		internal static int Compute( UpLo uplo, int n, ComplexDouble[] A, int lda  ){
			ArgumentCheck(uplo, n, A, lda);
			return dna_lapack_zpotri(uplo, n, A, lda);
		}

		[DllImport(dnA.Utility.Configuration.BLASLibrary, ExactSpelling=true, SetLastError=false)]
		private static extern int dna_lapack_spotri( UpLo uplo, int n, [In,Out]float[] A, int lda );

		[DllImport(dnA.Utility.Configuration.BLASLibrary, ExactSpelling=true, SetLastError=false)]
		private static extern int dna_lapack_dpotri( UpLo uplo, int n, [In,Out]double[] A, int lda );

		[DllImport(dnA.Utility.Configuration.BLASLibrary, ExactSpelling=true, SetLastError=false)]
		private static extern int dna_lapack_cpotri( UpLo uplo, int n, [In,Out]ComplexFloat[] A, int lda );

		[DllImport(dnA.Utility.Configuration.BLASLibrary, ExactSpelling=true, SetLastError=false)]
		private static extern int dna_lapack_zpotri( UpLo uplo, int n, [In,Out]ComplexDouble[] A, int lda );
	}
}
#endif